<?php
class GetNews extends Config
{
	
	var $postId = string;
	var $postTitle = string;
	var $postMessage = string;
	var $postTags = string;
	var $postUrl = string;
	var $postSee = string;
	var $postDate = string;
	function getPostData($post, $act = "byID")
	{
		try
		{
			if ($act == "byID")
			{
				$post = intval($post);
				$query = "SELECT `title`, `message`, `tags`, `url`, `date` 
							FROM `". $this -> DB_PREFIX ."blog` 
							WHERE `id` = '". $post ."';";
				$get = $this -> sql($query);
				$data = mysql_fetch_array($get);
				
				$this -> postUrl = $data['url'];
				$this -> sql("UPDATE `". $this -> DB_PREFIX ."blog` SET `see` = `see`+ 1 WHERE `id` = '". $post ."'");
			}
			if ($act == "byUrl")
			{
				$post = mysql_real_escape_string($post);
				$query = "SELECT `id`, `title`, `message`, `tags`, `see`, `date` 
							FROM `". $this -> DB_PREFIX ."blog` 
							WHERE `url` = '". $post ."';";
				$get = $this -> sql($query);
				$data = mysql_fetch_array($get);
				
				$this -> postId = $data['id'];
				$this -> postSee = $data['see'];
				$this -> sql("UPDATE `". $this -> DB_PREFIX ."blog` SET `see` = `see`+ 1 WHERE `id` = '". $data['id'] ."'");
			}
			$this -> postTitle = $data['title'];
			$this -> postMessage = $data['message'];
			$this -> postTags = $data['tags'];
			$this -> postDate = $data['date'];
		}
		catch (Exception $e)
		{
			return "Error in News Getting";
		}
	}
	
	function printTags($tagString)
	{
		$tags = explode(',', $tagString);
		foreach($tags as $tag) 
		{
			echo '<a href="'. HOME . MYDIR .'tags/'. trim($tag) .'">'. $tag .'</a> ';
		}
	}
	
	function getPostName($postId)
	{
		$query = "SELECT `title` FROM `". $this -> DB_PREFIX ."blog` WHERE `id` = '". $postId ."';";
		$get = $this -> sql($query);
		$data = mysql_fetch_array($get);
		return $data['title'];
	}
	
	function getLastId($tableName, $column)
	{
		$query = "SELECT `". $column ."` FROM `". $this -> DB_PREFIX . $tableName ."` ORDER BY `". $column ."` DESC LIMIT 1";
		$select = mysql_query($query);
		$data = mysql_fetch_array($select);
		return $data[$column];
	}
	
}

?>